define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'shop/index' + location.search,
                    // add_url: 'shop/add',
                    // edit_url: 'shop/edit',
                    // del_url: 'shop/del',
                    table: 'shop',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                commonSearch: true,
                showToggle: false,
                showColumns: false,
                showExport: false,
                exportDataType: false,
                columns: [
                    [
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('用户ID')},
                        {field: 'real_name', title: __('真实姓名')},
                        {field: 'card_number', title: __('身份证号码')},
                        {field: 'mobile', title: __('联系电话')},
                        {field: 'shop_name', title: __('店铺名称')},
                        {field: 'shop_logo', title: __('店铺logo'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'shop_address', title: __('店铺地址'), formatter: Table.api.formatter.content},
                        {field: 'front_card_image', title: __('身份证正面'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'back_card_image', title: __('身份证背面'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'license_image', title: __('营业执照'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'drugs_image', title: __('药品经营许可证'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'status', title: __('审核状态'), searchList: {"0":__('待审核'),"1":__('审核通过'),"2":__('审核失败')}, formatter: Table.api.formatter.status},
                        {field: 'start_time', title: __('入驻时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'end_time', title: __('套餐结束时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'deposit', title: __('押金')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate_auth1',
                            title: __('操作'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'auth1_pass',
                                    title: __('通过'),
                                    text: __('通过'),
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    // icon: 'fa fa-check',
                                    confirm: '确认通过当前店铺入驻？',
                                    url: 'shop/auth_deal?type=1',
                                    success: function (data, ret) {
                                        //如果需要阻止成功提示，则必须使用return false;
                                        //return false;
                                        $(".btn-refresh").trigger("click");
                                    },

                                    error: function (data, ret) {
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                },
                                {
                                    name: 'auth1_no',
                                    title: __('拒绝'),
                                    text: __('驳回'),
                                    classname: 'btn btn-xs btn-danger btn-magic btn-ajax',
                                    // icon: 'fa fa-times',
                                    confirm: '确认拒绝当前店铺入驻？',
                                    url: 'shop/auth_deal?type=2',
                                    success: function (data, ret) {
                                        //如果需要阻止成功提示，则必须使用return false;
                                        //return false;
                                        $(".btn-refresh").trigger("click");
                                    },
                                    error: function (data, ret) {
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                },
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        shop: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'shop/shop' + location.search,
                    // add_url: 'shop/add',
                    edit_url: 'shop/edit',
                    // del_url: 'shop/del',
                    table: 'shop',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                commonSearch: true,
                showToggle: false,
                showColumns: false,
                showExport: false,
                exportDataType: false,
                columns: [
                    [
                        {field: 'real_name', title: __('真实姓名')},
                        {field: 'card_number', title: __('身份证号码')},
                        {field: 'mobile', title: __('联系电话')},
                        {field: 'shop_name', title: __('店铺名称')},
                        {field: 'shop_logo', title: __('店铺logo'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'shop_address', title: __('店铺地址'), formatter: Table.api.formatter.content},
                        {field: 'money', title: __('店铺余额')},
                        {field: 'price', title: __('待入账金额')},
                        {field: 'start_time', title: __('入驻时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'end_time', title: __('套餐结束时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'deposit', title: __('押金')},
                        {
                            field: 'operate_auth1',
                            title: __('操作'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'cash',
                                    title: __('提现'),
                                    text: __('提现'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    // icon: 'fa fa-list',
                                    url: 'shop/cash?id={ids}',
                                    callback: function (data) {
                                    }
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        cash: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});